export function colorRender(z, renderType) {
  if (z < 1) z *= 10
  let ret
  let z_format = (z + 3) / 6.0
  if (z_format > 1.0) {
    z_format = 1.0
  } else if (z_format < 0.0) {
    z_format = 0.0
  }

  if (renderType && renderType === 'gorgeous') {
    let _color = hsvToRgb(z_format, 1.2, 1.2)
    ret = [_color[0], _color[1], _color[2]]
  } else if (renderType && renderType === 'simple') {
    if (z < 0) {
      ret = [177 / 255.0, 212 / 255.0, 219 / 255.0]
    } else {
      ret = [0, 1, 0]
    }
  } else {
    ret = [1, 1, 1]
  }

  return ret
}

export function hsvToRgb(h, s, v) {
  var i = parseInt(h * 6.0)
  var f = h * 6.0 - i
  var p = v * (1.0 - s)
  var q = v * (1.0 - s * f)
  var t = v * (1.0 - s * (1.0 - f))
  i = i % 6
  var r = 0,
    g = 0,
    b = 0
  if (i == 0) {
    r = v
    g = t
    b = p
  } else if (i == 1) {
    r = q
    g = v
    b = p
  } else if (i == 2) {
    r = p
    g = v
    b = t
  } else if (i == 3) {
    r = p
    g = q
    b = v
  } else if (i == 4) {
    r = t
    g = p
    b = v
  } else if (i == 5) {
    r = t
    g = p
    b = v
  }
  return [r, g, b]
}
